package com.hspedu.transformation;

import java.io.*;

/**
 * @author DL5O
 * @version 1.0
 * 演示使用InputStreamReader转换流解决中文乱码问题
 * 将字节流FileInputStream 转成字符流 InputStreamReader，指定utf-8/gdk
 */
public class InputStreamReader_ {
    public static void main(String[] args) throws IOException {
        String filePath = "d:\\story.txt";
        //1.把FileInputStream 转成 InputStreamReader
        //2.指定编码 gkd
        //InputStreamReader isr = new InputStreamReader(new FileInputStream(filePath),"gbk");
        //3.使用BufferedReader 传入 Buffered
        //BufferedReader br = new BufferedReader(isr);

        //将2和3合在一起写
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "gbk"));

        //4.读取
        String s = br.readLine();
        System.out.println("读取内容="+s);
        //5.关流
        br.close();
    }
}
